/* 
 *  Copyright (C) 2006 James Young
 * `gurumind(a)gmail.com
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Xml;

namespace IPDEditor
{
    public class EditorSetting : ConfigurationElement
    {
        RecordEditorList rel;
        public EditorSetting()
        {
            rel = new RecordEditorList();
        }

        [ConfigurationProperty("RecordEditor")]
        public RecordEditorList EditorLists
        {
            get
            {
                return (RecordEditorList)base["RecordEditor"];
            }
        }
    }

    public class RecordEditorList : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new RecordEditor("default Editor");
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            RecordEditor re = element as RecordEditor;
            if (re == null)
                return "default Editor";
            else
                return re.RecordType;
        }
    }

    public class RecordEditor : System.Configuration.ConfigurationElement
    {
        public RecordEditor(string recordType)
        {
            this["recordType"] = recordType;
        }

        [ConfigurationProperty("recordType")]
        public string RecordType
        {
            get { return (string)this["recordType"]; }
            set { this["recordType"] =value ;}
        }
    }

    //public sealed class EditorSettingSection : System.Configuration.ConfigurationSection
    //{
    //    private static ConfigurationProperty _recordEditors = new ConfigurationProperty("EditorSetting", typeof(RecordEditorSettingsCollection),
    //            null, ConfigurationPropertyOptions.None);

    //    private static ConfigurationPropertyCollection _properties;

    //    public EditorSettingSection()
    //    {
    //        _properties = new ConfigurationPropertyCollection();
    //        _properties.Add(_recordEditors);
    //    }

    //    //[ConfigurationProperty("EditorSetting")]
    //    //public RecordEditorSettingsCollection RecordEditors
    //    //{
    //    //    get { return (RecordEditorSettingsCollection)base[_recordEditors]; }
    //    //    set { base[_recordEditors] = value; }
    //    //}

    //    protected override ConfigurationPropertyCollection Properties
    //    {
    //        get
    //        {
    //            return _properties;
    //        }
    //    }
    //}

    //[ConfigurationCollection(typeof(RecordEditorSettingsCollection))]
    //public sealed class RecordEditorSettingsCollection : ConfigurationElementCollection
    //{
    //    private static readonly ConfigurationProperty _editors = new ConfigurationProperty(null,
    //        typeof(RecordEditorSettingsCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);

    //    private static ConfigurationPropertyCollection _properties = new ConfigurationPropertyCollection();
        
    //    public RecordEditorSettingsCollection()
    //    {

    //    }

    //    public RecordEditorSettings this[int index]
    //    {
    //        get
    //        {
    //            return (RecordEditorSettings)base.BaseGet(index);
    //        }
    //        set
    //        {
    //            base.BaseAdd(index, value);
    //        }
    //    }

    //    [ConfigurationProperty("RecordEditor", IsRequired = true)]
    //    //[StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    //    public string Name
    //    {
    //        get
    //        {
    //            return (string)this["RecordEditor"];
    //        }
    //        set
    //        {
    //            this["RecordEditor"] = value;
    //        }
    //    }

    //    protected override ConfigurationPropertyCollection Properties
    //    {
    //        get
    //        {
    //            return _properties;
    //        }
    //    }

    //    protected override string ElementName
    //    {
    //        get
    //        {
    //            return "RecordEditor";
    //        }
    //    }

    //    protected override ConfigurationElement CreateNewElement()
    //    {
    //        return new RecordEditorSettings();
    //    }

    //    protected override object GetElementKey(ConfigurationElement element)
    //    {
    //        string key = ((RecordEditorSettings)element).Name;
    //        return key;
    //    }
    //}

    //public sealed class RecordEditorSettings : ConfigurationElement
    //{
    //    private readonly ConfigurationProperty _name = new ConfigurationProperty("recordType", typeof(string), null, ConfigurationPropertyOptions.IsRequired);
    //    //private readonly ConfigurationProperty _fields = new ConfigurationProperty("Field", typeof(FieldSettingsCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);

    //    private readonly ConfigurationPropertyCollection _properties;

    //    public RecordEditorSettings()
    //    {
    //        _properties = new ConfigurationPropertyCollection();
    //        _properties.Add(_name);
    //        //_properties.Add(_fields);
    //    }

    //    [ConfigurationProperty("recordType", IsRequired = true)]
    //    //[StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    //    public string Name
    //    {
    //        get
    //        {
    //            return (string)this["recordType"];
    //        }
    //        set
    //        {
    //            this["recordType"] = value;
    //        }
    //    }

    //    //[ConfigurationProperty("Field")]
    //    //public FieldSettingsCollection Fields
    //    //{
    //    //    get { return (FieldSettingsCollection)base[_fields]; }
    //    //    set { base[_fields] = value; }
    //    //}

    //    //protected override ConfigurationPropertyCollection Properties
    //    //{
    //    //    get
    //    //    {
    //    //        return _properties;
    //    //    }
    //    //}
    //}

    //[ConfigurationCollection(typeof(FieldSettings))]
    //public sealed class FieldSettingsCollection : ConfigurationElementCollection
    //{
    //    private static readonly ConfigurationProperty _fields = new ConfigurationProperty("Field",
    //        typeof(FieldSettings), null, ConfigurationPropertyOptions.IsDefaultCollection);

    //    private static ConfigurationPropertyCollection _properties;
    //    public FieldSettingsCollection()
    //    {
    //        _properties = new ConfigurationPropertyCollection();
    //        _properties.Add(_fields);
    //    }

    //    [ConfigurationProperty("fieldName", IsRequired = true)]
    //    //[StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    //    public string FieldName
    //    {
    //        get
    //        {
    //            return (string)this["fieldName"];
    //        }
    //        set
    //        {
    //            this["fieldName"] = value;
    //        }
    //    }

    //    [ConfigurationProperty("dataType", IsRequired = true)]
    //    //[StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    //    public string DataType
    //    {
    //        get
    //        {
    //            return (string)this["dataType"];
    //        }
    //        set
    //        {
    //            this["dataType"] = value;
    //        }
    //    }

    //    [ConfigurationProperty("visualType", IsRequired = true)]
    //    //[StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    //    public string VisualType
    //    {
    //        get
    //        {
    //            return (string)this["visualType"];
    //        }
    //        set
    //        {
    //            this["visualType"] = value;
    //        }
    //    }

    //    public FieldSettings this[int index]
    //    {
    //        get
    //        {
    //            return (FieldSettings)base.BaseGet(index);
    //        }
    //        set
    //        {
    //            base.BaseAdd(index, value);
    //        }
    //    }

    //    public void Add(FieldSettings field)
    //    {
    //        BaseAdd(field);
    //    }

    //    public void Clear()
    //    {
    //        BaseClear();
    //    }

    //    public void Remove(string name)
    //    {
    //        BaseRemove(name);
    //    }

    //    protected override ConfigurationElement CreateNewElement()
    //    {
    //        return new FieldSettings();
    //    }

    //    protected override object GetElementKey(ConfigurationElement element)
    //    {
    //        string key = ((FieldSettings)element).Name;
    //        if (string.IsNullOrEmpty(key))
    //        {
    //            key = ((FieldSettings)element).DataType;
    //        }
    //        return key;
    //    }
    //}

    //public sealed class FieldSettings : ConfigurationElement
    //{
    //    private readonly ConfigurationProperty _name = new ConfigurationProperty("fieldName", typeof(string),
    //        "", ConfigurationPropertyOptions.IsRequired);
    //    private readonly ConfigurationProperty _dataType = new ConfigurationProperty("dataType", typeof(string),
    //        "", ConfigurationPropertyOptions.IsRequired);
    //    private readonly ConfigurationProperty _visualType = new ConfigurationProperty("visualType", typeof(string),
    //        "", ConfigurationPropertyOptions.IsRequired);

    //    private readonly ConfigurationPropertyCollection _properties;

    //    public FieldSettings()
    //    {
    //        _properties = new ConfigurationPropertyCollection();
    //        _properties.Add(_name);
    //        _properties.Add(_dataType);
    //        _properties.Add(_visualType);
    //    }

    //    [ConfigurationProperty("fieldName")]
    //    [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    //    public string Name
    //    {
    //        get { return (string)base[this._name]; }
    //        set { base[this._name] = value; }
    //    }

    //    [ConfigurationProperty("dataType")]
    //    [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    //    public string DataType
    //    {
    //        get { return (string)base[this._dataType]; }
    //        set { base[this._dataType] = value; }
    //    }

    //    [ConfigurationProperty("visualType")]
    //    [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
    //    public string VisualType
    //    {
    //        get { return (string)base[this._visualType]; }
    //        set { base[this._visualType] = value; }
    //    }

    //}

}
